/*
商城界面，暂时弃用，等后续需要介入内购sdk的时候再使用，还没有完成调试
*/
cc.Class({
    extends: cc.Component,

    properties: {
        parent:{
            default:null,
            type:cc.Node
        },
        pay_item:{
            default:null,
            type:cc.Node
        },
        isInit:false,
    },

    onLoad: function () {

    },

    onInit:function(){
        //des:购买获得3张房卡       应付金额：6元
        this.payItemViewNode = this.node.getChildByName("payItemView");
        this.payItemView = this.payItemViewNode.getChildByName("view").getChildByName("content");
        this.payItemList = [];
        this.payItemBeginX = 120;
        this.payItemOffsetX = 260;
        this.curSelect = -1;

        this.isInit = true;
    },

    initPayView:function(){
        this.payConfig = {};
        var self = this;
        var itemCount = 0;
        for(var i in payConfig)
        {
            var curData = payConfig[i];

            var newPayItem = cc.instantiate(self.pay_item);
            self.payItemList[itemCount] = newPayItem;
            self.payItemView.addChild(newPayItem);
            newPayItem.active = true;
            newPayItem.x = self.payItemBeginX - self.payItemOffsetX * itemCount;

            var mainImg = newPayItem.getChildByName("mainImg").getComponent("cc.Sprite");
            var tips = newPayItem.getChildByName("tips").getComponent("cc.Label");
            var cost = newPayItem.getChildByName("cost").getComponent("cc.Label");
            // var btnGet = newPayItem.getChildByName("toyGet").getComponent("cc.Button");

            // var sellCall = function(){
            //     self.sellItem(sellCall.index,sellCall.itemId);
            // };
            // sellCall.index = i;
            // sellCall.itemId = curData;
            // btnSell.node.on(cc.Node.EventType.TOUCH_END, sellCall, self);

            itemCount++;
        }
        self.payItemView.height = 800 + (itemCount-3)*this.payItemBeginX;
    },

    btnBuyClick:function(event, customEventData){
        console.log("btnBuyClick!!!!!!!!");
    },

    showLayer:function(){
        if(this.isInit == false)
            this.onInit();
        this.node.active = true;
    },

    hideLayer:function(){
        this.node.active = false;
    },
});
